<template>
    <div class="BusinessProcessAdd">
        <p style="margin:10px">
            <el-button @click="backHomepage" size="mini" type="primary">返回上一级</el-button>
        </p>
        <p class="title">房屋风险提示单处置</p>
        <div class="BusinessProcessAdd_con">
            <div v-for="(item, index) in from.preventBaseInfoDtoList" :key='index'>
                <p class="subTitle"><span class="line"></span>房屋基本信息</p>
                <van-form :readonly="readonly" validate-firstm>
                    <van-field label="户主姓名" name="householderName" readonly v-model="rowData[index].householderName"
                        placeholder="" />
                    <van-field label="户主联系电话" name="householderPhone" readonly v-model="rowData[index].householderPhone"
                        placeholder="" />
                    <van-field label="使用人姓名" name="propertyPersonName" v-model="rowData[index].propertyPersonName"
                        placeholder="请输入使用人姓名" />
                    <van-field label="使用人联系电话" name="propertyPersonPhone" v-model="rowData[index].propertyPersonPhone"
                        placeholder="请输入使用人联系电话" />
                    <van-field label="房屋地址" readonly name="adress" v-model="rowData[index].adress" placeholder=" " />
                    <van-field clickable readonly name="picker" :value="item.appraiseLevel | inUseName(Enum.JDDJ)"
                        label="鉴定情况" placeholder=" " />
                    <!-- <van-popup v-model="Enum.ISJDDJ" position="bottom" get-container="#popup">
                        <van-picker show-toolbar ref="vanpopup" :columns="Enum.JDDJ" value-key="name"
                            @confirm="onConfirm1(item)" @cancel="Enum.ISJDDJ = false" />
                    </van-popup> -->
                </van-form>
                <p class="subTitle"><span class="line"></span>转移人员信息</p>
                <van-form ref="ruleFormZY" :readonly="readonly" validate-firstm scroll-to-error>
                    <van-field required clickable readonly name="picker"
                        :value="ruleForm[index].isLive | inUseName(Enum.JZRY)" label="人员居住情况" placeholder="请选择人员居住情况"
                        @click="Enum.ISJZRY = true" :rules="rules" />
                    <van-popup v-model="Enum.ISJZRY" position="bottom" get-container="#popup">
                        <van-picker show-toolbar ref="vanpopup" :columns="Enum.JZRY" value-key="name"
                            @confirm="onConfirm7(ruleForm[index])" @cancel="Enum.ISJZRY = false" />
                    </van-popup>
                </van-form>
                <div v-if="ruleForm[index].isLive == 1">
                    <p style="padding: 0 10px;" v-if='!readonly'>
                        <van-button size="small" color="dodgerblue" @click="add(index)">添加</van-button>
                        <van-button size="small" color="dodgerblue" @click="updata(index)">修改</van-button>
                        <van-button size="small" color="dodgerblue" @click="del(index)">删除</van-button>
                    </p>
                    <div style="padding: 0 10px;margin-top: 10px;">
                        <el-table :data="tableData[index]" style="width: 100%;margin-bottom: 10px;" border stripe
                            :row-class-name="tableRowClassName"
                            :header-cell-style="{ 'background-color': '#F5F7FA', 'color': '#000' }" highlight-current-row
                            @row-click="rowClick">
                            <el-table-column align="center" width="60px" label="序号" type="index"></el-table-column>
                            <el-table-column prop="czrkxm" label="姓名" />
                            <el-table-column prop="czrkgmsfhm" label="身份证号" />
                            <el-table-column prop="phone" label="手机" />
                            <el-table-column prop="isdifficult" label="是否残疾人、孤寡老人等重点群体">
                                <template slot-scope="scope">
                                    {{ scope.row.isdifficult | inUseName(Enum.IS) }}
                                </template>
                            </el-table-column>
                            <!-- <el-table-column prop="isRemind" label="是否完成风险提醒">
                                <template slot-scope="scope">
                                    {{ scope.row.isRemind | inUseName(Enum.IS) }}
                                </template>
                            </el-table-column> -->
                            <el-table-column prop="isRemove" label="是否转移">
                                <template slot-scope="scope">
                                    {{ scope.row.isRemove | inUseName(Enum.IS) }}
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                </div>
                <van-form ref="ruleFormZY" :readonly="readonly" validate-firstm scroll-to-error>
                    <van-field required label="转移责任人姓名" name="zyzrrsj" v-model="ruleForm[index].zyzrrsj" :rules="rules"
                        placeholder="请输入转移责任人姓名" />
                    <van-field required label="转移责任人手机" name="zyzrrxm" v-model="ruleForm[index].zyzrrxm" :rules="rulesSJH"
                        placeholder="请输入转移责任人手机" />
                    <van-field label="补录人" name="recordOperator" v-model="ruleForm[index].recordOperator"
                        placeholder="请输入补录人" />
                    <van-field label="补录时间" name="recordTime" v-model="ruleForm[index].recordTime"
                        placeholder="系统生成无需填写" />
                </van-form>
            </div>
        </div>
        <div class="BusinessProcessAdd_con">
            <p class="subTitle"><span class="line"></span>风险处置信息</p>
            <div v-for="(item, i) in from.housePreventTaskDealInfoList" :key='i'>
                <p style="line-height: 30px;margin-left:10px;">
                    {{ item.riskDealDate ? item.riskDealDate : nowData }} {{ item.riskLevel | inUseName(Enum.FXDJ) }}风险
                </p>
                <van-form :readonly="readonly" validate-firstm>
                    <van-field readonly label="风险名称" name="taskName" v-model="item.taskName" />
                    <van-field readonly label="风险提示时间" clickable name="datetimePicker" :value="item.riskRemindTime" />
                    <!-- <van-popup v-model="showPickerq" position="bottom">
                        <van-datetime-picker ref="vanpopup1" v-model="currentDate" type="date" title="选择年月日"
                            @cancel="showPickerq = false" @confirm="onConfirmRQ(item)" />
                    </van-popup> -->
                    <van-field clickable readonly name="picker" :value="item.riskLevel | inUseName(Enum.FXDJ)"
                        label="风险级别" />
                    <!-- <van-popup v-model="Enum.ISFXDJ" position="bottom" get-container="#popup">
                        <van-picker show-toolbar ref="vanpopup2" :columns="Enum.FXDJ" value-key="name"
                            @confirm="onConfirm2(item)" @cancel="readonly ? '' : Enum.ISFXDJ = false" />
                    </van-popup> -->
                    <van-field readonly label="风险处置要求" name="riskDealRequire" type="textarea" rows="4" autosize
                        v-model="item.riskDealRequire" />
                    <van-field label="风险处置说明" name="riskDealComments" type="textarea" rows="4" autosize
                        placeholder="请输入风险处置说明" v-model="item.riskDealComments" />
                    <template v-if="item.riskLevel == 0 || item.riskLevel == 1">
                        <van-field readonly label="应转移人员" name="shouldRemovePerople" v-model="item.shouldRemovePerople"
                            placeholder=" " />
                        <van-field readonly label="已转移人员" name="alreadyRemovePeople" v-model="item.alreadyRemovePeople"
                            placeholder=" " />
                    </template>
                    <template v-else-if="item.riskLevel == 2">
                        <van-field readonly label="应转移人员" name="shouldRemovePerople" v-model="item.shouldRemovePerople"
                            placeholder=" " />
                    </template>
                    <template v-else>
                        <van-field readonly label="风险处置人" name="riskDealPersonName" v-model="item.riskDealPersonName"
                            placeholder=" " />
                        <van-field readonly label="风险处置时间" name="riskDealDate" v-model="item.riskDealDate"
                            placeholder=" " />
                        <van-field clickable readonly name="picker" :value="item.reportStatus | inUseName(Enum.IS)"
                            label="是否完成风险提醒" placeholder="请选择是否完成风险提醒" @click="readonly ? '' : Enum.ISIS = true" />
                        <van-popup v-model="Enum.ISIS" position="bottom" get-container="#popup">
                            <van-picker show-toolbar ref="vanpopup3" :columns="Enum.IS" value-key="name"
                                @confirm="onConfirm3(item)" @cancel="Enum.ISIS = false" />
                        </van-popup>
                    </template>
                </van-form>
            </div>
        </div>
        <p class="buttonfooter" v-if="!readonly">
            <van-button color="dodgerblue" @click="save(1)">保存</van-button>
            <van-button color="dodgerblue" @click="save(2)">提交</van-button>
        </p>
        <van-popup class="popupDialog" v-model="show">
            <div class="dialog-title-text">转移人员信息</div>
            <van-form ref="ruleFormAdd" validate-firstm>
                <van-field label="姓名" name="czrkxm" v-model="fromVal.czrkxm" :readonly="fromVal.czrkgmsfhm == idCard"
                    placeholder="请输入姓名" :rules="rules" />
                <van-field label="身份证号" name="czrkgmsfhm" v-model="fromVal.czrkgmsfhm"
                    :readonly="fromVal.czrkgmsfhm == idCard" placeholder="请输入身份证号" :rules="rulesSFZH" />
                <van-field label="手机号" name="phone" v-model="fromVal.phone" placeholder="请输入手机号"
                    :rules="fromVal.phone ? rulesSJH : []" />
                <van-field label-width="120px" clickable readonly name="picker"
                    :value="fromVal.isdifficult | inUseName(Enum.IS)" label="是否残疾人、孤寡老人等重点群体" placeholder="请选择"
                    @click="Enum.ISIS1 = true" />
                <van-popup v-model="Enum.ISIS1" position="bottom" get-container="#popup">
                    <van-picker show-toolbar :columns="Enum.IS" value-key="name" @confirm="onConfirm4"
                        @cancel="Enum.ISIS1 = false" />
                </van-popup>
                <!-- <van-field label-width="120px" clickable readonly name="picker"
                    :value="fromVal.isRemind | inUseName(Enum.IS)" label="是否完成风险提醒" placeholder="请选择"
                    @click="Enum.ISIS2 = true" />
                <van-popup v-model="Enum.ISIS2" position="bottom" get-container="#popup">
                    <van-picker show-toolbar :columns="Enum.IS" value-key="name" @confirm="onConfirm5"
                        @cancel="Enum.ISIS2 = false" />
                </van-popup> -->
                <van-field label-width="120px" clickable readonly name="picker"
                    :value="fromVal.isRemove | inUseName(Enum.IS)" label="是否转移" placeholder="请选择"
                    @click="Enum.ISIS3 = true" />
                <van-popup v-model="Enum.ISIS3" position="bottom" get-container="#popup">
                    <van-picker show-toolbar :columns="Enum.IS" value-key="name" @confirm="onConfirm6"
                        @cancel="Enum.ISIS3 = false" />
                </van-popup>
                <p class="buttonfooter">
                    <van-button size="small" color="dodgerblue" @click="addSure()">确定</van-button>
                    <van-button size="small" color="dodgerblue" @click="show = false">取消</van-button>
                </p>
            </van-form>
        </van-popup>
    </div>
</template>
<script>
import { FileServerProxy } from "@/utils/api";
import axios from "axios";
import dd from 'gdt-jsapi'
import { async } from "q";
export default {
    name: 'BusinessProcessAdd',
    data() {
        return {
            BaseUrl: window.g.BaseURL,
            nowData: "",
            rowIndex: -1,
            showPickerq: false,
            show: false,
            currentDate: new Date(),
            idCard: null,
            rules: [{ required: true, message: ' ' }],
            rulesSJH: [
                {
                    required: true,
                    message: "请填写手机号码",
                    trigger: "blur",
                },
                {
                    pattern: /\d{11}/,
                    message: "请填写正确手机号码",
                    trigger: "blur",
                },
            ],
            rulesSFZH: [
                {
                    required: true,
                    message: "请填写身份证号",
                    trigger: "change",
                },
                {
                    pattern: /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/,
                    message: "证件号码格式有误！",
                    trigger: "blur",
                },
            ],
            isDisabled: [],
            Enum: {
                ISIS: false,
                ISIS1: false,
                ISIS2: false,
                ISIS3: false,
                IS: [
                    {
                        name: '是',
                        value: 1
                    },
                    {
                        name: '否',
                        value: 0
                    }
                ],
                SB: [
                    {
                        name: '未上报',
                        value: -1
                    },
                    {
                        name: '待上报',
                        value: 0
                    },
                    {
                        name: '已上报',
                        value: 1
                    }
                ],
                ISFXDJ: false,
                FXDJ: [
                    {
                        name: 'Ⅰ级',
                        value: 0
                    },
                    {
                        name: 'Ⅱ级',
                        value: 1
                    },
                    {
                        name: 'Ⅲ级',
                        value: 2
                    },
                    {
                        name: 'Ⅳ级',
                        value: 3
                    },
                    {
                        name: 'Ⅴ级',
                        value: 4
                    }
                ],
                ISJDDJ: false,
                JDDJ: [
                    {
                        name: 'A级',
                        value: 1
                    },
                    {
                        name: 'B级',
                        value: 2
                    },
                    {
                        name: 'C级',
                        value: 3
                    },
                    {
                        name: 'D级',
                        value: 4
                    }
                ],
                ISJZRY: false,
                JZRY: [
                    {
                        name: '有人居住',
                        value: 1
                    },
                    {
                        name: '无人居住',
                        value: 0
                    }
                ],
            },
            from: {
                "housePreventTaskDealInfoList": [],
                "preventBaseInfoDtoList": []
            },
            fromVal: {
                "czrkxm": "",  // 姓名
                "czrkgmsfhm": "",  // 身份证号
                "phone": "",//手机号
                "isdifficult": null,//是否残疾人、孤寡老人等重点群体 0是 1不是
                "czrkhh": null, //户号
                "isRemind": null,
                "isRemove": null,
            },
            statusType: "",
            tableData: [],
            ruleForm: [],
            ids: [],
            czrkhh: [], //新增家庭成员信息需根据户号做关联
            rowIndex: -1
        }
    },
    props: {
        rowData: Array,
        readonly: Boolean
    },
    filters: {
        inUseName: function (msg, data) {
            let name = ''
            data.forEach(item => {
                if (item.value == msg) {
                    name = item.name
                }
            })
            return name
        },
    },
    watch: {},
    methods: {
        //返回
        backHomepage() {
            if (this.readonly) {

            } else {
                this.$parent.getchaXun()
            }
            this.$parent.showList = true
        },
        onConfirm1(item) {
            item.appraiseLevel = this.$refs.vanpopup[0].getValues()[0].value;
            this.Enum.ISJDDJ = false;
        },
        onConfirm2(item) {
            item.riskLevel = this.$refs.vanpopup2[0].getValues()[0].value;
            this.Enum.ISFXDJ = false;
        },
        onConfirm3(item) {
            item.reportStatus = this.$refs.vanpopup3[0].getValues()[0].value;
            this.Enum.ISIS = false;
        },
        onConfirm4(value) {
            this.fromVal.isdifficult = value.value;
            this.Enum.ISIS1 = false;
        },
        onConfirm5(value) {
            this.fromVal.isRemind = value.value;
            this.Enum.ISIS2 = false;
        },
        onConfirm6(value) {
            this.fromVal.isRemove = value.value;
            this.Enum.ISIS3 = false;
        },
        onConfirm7(item) {
            item.isLive = this.$refs.vanpopup[0].getValues()[0].value;
            this.Enum.ISJZRY = false;
        },
        onConfirmRQ(item) {
            let val = this.$refs.vanpopup1.getValues()[0].value;
            let year = val.getFullYear();
            let month = val.getMonth() + 1;
            let day = val.getDate();
            let hour = val.getHours();
            let minute = val.getMinutes();
            let seconds = val.getSeconds();
            if (month >= 1 && month <= 9) {
                month = `0${month}`;
            }
            if (day >= 1 && day <= 9) {
                day = `0${day}`;
            }
            if (hour >= 0 && hour <= 9) {
                hour = `0${hour}`;
            }
            if (minute >= 0 && minute <= 9) {
                minute = `0${minute}`;
            }
            if (seconds >= 0 && seconds <= 9) {
                seconds = `0${seconds}`;
            }
            item.riskRemindTime = `${year}-${month}-${day} ${hour}:${minute}:${seconds}`;
            this.showPickerq = false;
        },
        //计算
        changeVal() {
            let riskLevel = this.from.housePreventTaskDealInfoList[0].riskLevel
            if (riskLevel == 0 || riskLevel == 1) {
                let alreadyRemovePeople = 0;
                this.tableData.forEach(item => {
                    item.forEach(items => {
                        items.isRemove == 1 ? alreadyRemovePeople++ : ''
                    })
                })
                this.from.housePreventTaskDealInfoList[0].alreadyRemovePeople = alreadyRemovePeople
            }
            if (riskLevel == 0 || riskLevel == 1 || riskLevel == 2) {
                let shouldRemovePerople = 0;
                this.tableData.forEach(item => {
                    shouldRemovePerople += item.length
                })
                this.from.housePreventTaskDealInfoList[0].shouldRemovePerople = shouldRemovePerople;
            }
        },
        //保存
        save: async function (type) {
            let num = 0;
            this.$refs.ruleFormZY.forEach(element => {
                element.validate().then((valid) => {
                    num++
                    this.changeVal()
                    if (num == this.$refs.ruleFormZY.length) {
                        let status = true
                        let quit = true;
                        let riskLevel = this.from.housePreventTaskDealInfoList[0].riskLevel
                        this.from.preventBaseInfoDtoList.forEach((item, index) => {
                            if (this.tableData.length > 0 && this.tableData[index].length > 0) {
                                item.alreadyRemovePeople = 0;
                                item.shouldRemovePerople = this.tableData[index].length;
                                this.tableData[index].forEach(items => {
                                    items.isRemove == 1 ? item.alreadyRemovePeople++ : '';
                                    if (!items.czrkxm || !items.czrkgmsfhm) {
                                        status = false;
                                    }
                                })
                                if (riskLevel != 0 && riskLevel != 1 && riskLevel != 2) {
                                    item.shouldRemovePerople = 0;
                                }
                            }
                            if (this.tableData[index].length) {
                                //let status = true
                                let list = new Set(this.tableData[index].map(x => {
                                    return x.czrkgmsfhm
                                }))
                                if (list.size != this.tableData[index].length) {
                                    quit = false;
                                }
                            }

                        })
                        if (status && quit) {
                            this.saveFrom(type)
                        }
                    }
                }, (err) => {
                    element.scrollToField(err[0].name, true)
                })
            })
        },
        saveFrom: async function (type) {
            let params = {};
            if (type == 1) {
                params['preventBaseInfoDtoList'] = this.from.preventBaseInfoDtoList;
                params['housePreventTaskDealInfoList'] = []
            } else if (type == 2) {
                params['preventBaseInfoDtoList'] = this.from.preventBaseInfoDtoList;
                params['housePreventTaskDealInfoList'] = this.from.housePreventTaskDealInfoList
            }
            this.saveBAseInfo()
            this.saveTableData()
            let webResult = await axios.post(this.BaseUrl + '/api/farmerHouse/housePreventTaskDealInfo/saveOrUpdateTaskDealInfo', params, {
                headers: {
                    isOutParam: true,
                },
            });
            if (webResult.data.data) {
                this.$toast.success(type == 1 ? "保存成功" : "提交成功");
                type == 1 ? '' : this.backHomepage()
            } else {
                this.$toast.fail(type == 1 ? "保存失败" : "提交失败")
            }
        },
        //把每一行的索引放进row
        tableRowClassName({ row, rowIndex }) {
            row.index = rowIndex;
        },
        //添加行
        add(index) {
            this.index = index;
            this.statusType = "add";
            for (var i in this.fromVal) {
                this.fromVal[i] = ""
            }
            this.show = true;
        },
        //修改
        updata(index) {
            this.index = index;
            this.statusType = "updata";
            this.idCard = this.rowData[index].idCard
            if (this.rowIndex > -1) {
                this.fromVal = JSON.parse(JSON.stringify(this.tableData[index][this.rowIndex]));
                this.show = true;
            } else {
                this.$toast.fail("请选中需要修改的数据");
            }
        },
        //删除行
        del(index) {
            this.statusType = "del";
            if (this.rowIndex > -1) {
                this.tableData[index].splice(this.rowIndex, 1);
                this.changeVal()
            } else {
                this.$toast.fail("请选中需要删除的数据");
            }
        },
        //
        addSure() {
            this.$refs.ruleFormAdd.validate().then((valid) => {
                let fromVal = JSON.parse(JSON.stringify(this.fromVal))
                if (this.statusType == "updata") {
                    for (var i in fromVal) {
                        this.$set(this.tableData[this.index][this.rowIndex], i, fromVal[i])
                    }
                    this.changeVal()
                    this.$forceUpdate()
                } else {
                    this.tableData[this.index].push(fromVal)
                }
                this.show = false;
            }, (err) => {
            })

        },
        //表格行点击
        rowClick(row) {
            this.rowIndex = row.index;
        },
        //获取家庭成员信息
        getTableData: async function (idCard, index) {
            let objectNoValue = "";
            if (this.rowData[index].objectNo) {
                objectNoValue = this.rowData[index].objectNo;
            } else {
                objectNoValue = "";
            }
            let res = await axios.get(this.BaseUrl + '/api/farmerHouse/houseFamliyMember/selectFamliyMember?idCard=' + idCard + '&checkNumber=' + this.rowData[index].checkNumber + '&objectNo=' + objectNoValue, {
                headers: {
                    isOutParam: true,
                },
            });
            this.tableData[index] = []
            this.czrkhh[index] = this.newGuid()
            this.ids[index] = []
            if (res.data.data && res.data.data.length > 0) {
                res.data.data.forEach(item => {
                    this.ids[index].push(item.id)
                    this.tableData[index].push(item)
                    this.czrkhh[index] = item.czrkhh
                })
                this.changeVal()
                this.$forceUpdate()
            } else {
                // 如果没有返回数据就调用大数据平台接口
                let _this = this;
                var p = {
                    appKey: "6738b790-69e8-11ec-a673-6805cab640a0",
                    accessCode: "4f54f932615d11ec87416805cab640a0",
                    cityCode: window.localStorage.getItem("citycode"),
                    params: { czrkgmsfhm: idCard }
                };
                const Result = await FileServerProxy(p);
                if (
                    Result.status == 200 &&
                    Result.data.data &&
                    Result.data.data.datas.length > 0
                ) {
                    let arr = []
                    Result.data.data.datas.forEach((items, index) => {
                        let obj = {}
                        for (var i in items.ELC_LICENCE_STRUCT.DATA) {
                            obj[i.toLowerCase()] = items.ELC_LICENCE_STRUCT.DATA[i]
                        }
                        arr.push(obj)
                    });
                    _this.tableData[index] = arr
                    _this.czrkhh[index] = Result.data.data.datas[0].ELC_LICENCE_STRUCT.DATA.CZRKHHID
                } else {
                    _this.tableData[index].push({
                        "czrkxm": _this.rowData[index].householderName,  // 姓名
                        "czrkgmsfhm": idCard,  // 身份证号
                        "phone": _this.rowData[index].householderPhone,//手机号
                        "isdifficult": null,//是否残疾人、孤寡老人等重点群体 0是 1不是
                        "czrkhh": _this.czrkhh[index], //户号
                        "isRemind": null,
                        "isRemove": null,
                        "yhfwbh": _this.rowData[index].checkNumber,
                        "objectNo": _this.rowData[index].fwid,
                    });
                }
                _this.changeVal()
                _this.$forceUpdate()
            }
        },
        //获取转移责任人信息
        getTransfer: async function (idCards, index) {
            let idCard = idCards
            let objectNoValue = "";
            this.$set(this.ruleForm, index, {})
            if (this.rowData[index].objectNo) {
                objectNoValue = this.rowData[index].objectNo;
            } else {
                objectNoValue = "";
            }
            let res = await axios.get(this.BaseUrl + '/api/farmerHouse/houseFamliyMember/selectTransfer?idCard=' + idCard + '&checkNumber=' + this.rowData[index].checkNumber + '&objectNo=' + objectNoValue, {
                headers: {
                    isOutParam: true,
                },
            });
            if (res.data.data) {
                for (const key in res.data.data) {
                    const element = res.data.data[key];
                    if (element != null) {
                        this.$set(this.ruleForm[index], key, element)
                    }
                }
                console.log(this.ruleForm[index])
                if (res.data.data.isLive == 1) {
                    this.getTableData(idCards, index)
                }
            } else {
                this.ruleForm[index] = {
                    zyzrrsj: "",
                    zyzrrxm: "",
                    isLive: "",
                    recordOperator: JSON.parse(window.localStorage.getItem('userName')).userName,
                    recordTime: this.getDate()
                }
            }
            this.$forceUpdate()
        },
        //
        saveTableData: async function () {
            this.from.preventBaseInfoDtoList.forEach((item, index) => {
                let p1 = null;
                if (this.ids.length > 0 && this.ids[index].length > 0) {
                    p1 = new Promise((resolve, reject) => {
                        axios.post(
                            `${this.BaseUrl}/api/farmerHouse/houseFamliyMember/delete`, this.ids[index], {
                            headers: {
                                "isOutParam": true,
                                "isOutParamS": true
                            }
                        }).then(res => {
                            resolve(res);
                        })
                    });
                } else {
                    p1 = new Promise((resolve, reject) => {
                        resolve(true);
                    });
                }
                p1.then((resolve, reject) => {
                    // if (this.tableData.length > 0 && this.tableData[index].length > 0) {
                        let p = this.ruleForm[index];
                        p["yhfwbh"] = this.rowData[index].checkNumber;
                        p["objectNo"] = this.rowData[index].fwid;
                        p['houseFamliyMemberList'] = [];
                        if (p.isLive == 1) {
                            this.tableData[index].forEach(item => {
                                p['houseFamliyMemberList'].push({
                                    "czrkxm": item.czrkxm,  // 姓名
                                    "czrkgmsfhm": item.czrkgmsfhm,  // 身份证号
                                    "phone": item.phone,//手机号
                                    "isdifficult": item.isdifficult,//是否残疾人、孤寡老人等重点群体 0是 1不是
                                    "czrkhh": this.czrkhh[index], //户号,
                                    "isRemind": item.isRemind,
                                    "isRemove": item.isRemove,
                                    "yhfwbh": this.rowData[index].checkNumber,
                                    "objectNo": this.rowData[index].fwid,
                                    //"yhfwbh": this.from.preventBaseInfoDtoList.yhfwbh,
                                })
                            })
                        } else {
                            p['houseFamliyMemberList'] = null
                        }

                        axios.post(
                            `${this.BaseUrl}/api/farmerHouse/houseFamliyMember/saveList/v2`, p, {
                            headers: {
                                "isOutParam": true,
                                "isOutParamS": true
                            }
                        }).then(res => {
                            if (res.data.data) {
                                // this.$message.success("家庭成员保存成功")
                            } else {
                                this.$message.error(this.rowData[index].householderName + "家庭成员信息保存失败")
                            }
                        })
                    // }
                })
            })
        },
        //提交
        submit() {
        },
        //保存修改的基本信息
        saveBAseInfo() {
            this.from.preventBaseInfoDtoList.forEach((items, index) => {
                let item = this.rowData[index];
                let params = {
                    "householderName": item.householderName ? item.householderName : null,
                    "householderPhone": item.householderPhone ? item.householderPhone : null,
                    "propertyPersonName": item.propertyPersonName ? item.propertyPersonName : null,
                    "propertyPersonPhone": item.propertyPersonPhone ? item.propertyPersonPhone : null,
                    "id": item.id,
                }
                axios.post(
                    `${this.BaseUrl}/api/farmerHouse/housePreventTyphoonFlood/updateHouseRemoldBaseInfo`, params, {
                    headers: {
                        "isOutParam": true,
                        "isOutParamS": true
                    }
                }).then(res => {
                    if (res.data.data) {
                        //this.$toast.success("房屋基本信息保存成功")
                    } else {
                        this.$toast.fail("房屋基本信息保存失败")
                    }
                })
            })
        },
        //获取风险处置信息
        getHousePreventTaskDealInfo: async function (id) {
            let res = await axios.get(this.BaseUrl + '/api/farmerHouse/housePreventTyphoonFlood/dealInfo/' + id, {
                headers: {
                    isOutParam: true,
                },
            });
            //  console.log(res)
            if (res.data.data) {
                let obj = this.from.housePreventTaskDealInfoList[0];
                for (var i in res.data.data) {
                    for (var k in obj) {
                        if (i == k && res.data.data[i]) {
                            obj[k] = res.data.data[i]
                        }
                    }
                }
            }
        },
    },
    mounted() {
        this.nowData = this.getDate();
        let riskLevel = []
        this.rowData.forEach((item, index) => {
            if (riskLevel.indexOf(item.riskLevel) == -1) {
                riskLevel.push(item.riskLevel)
                let obj = {
                    "alreadyRemovePeople": 0,
                    "cityCode": item.cityCode,
                    "createDate": item.createDate ? item.createDate : (this.readonly ? "" : this.getDate()),
                    "houseNum": this.rowData.length,
                    "id": "",
                    "isDelete": 0,
                    "isDownNum": 0,
                    "isRemindNum": 0,
                    "reportStatus": 0,
                    "riskDealComments": item.riskDealComments ? item.riskDealComments : "",
                    "riskDealDate": item.riskDealDate ? item.riskDealDate : (this.readonly ? "" : this.getDate()),
                    "riskDealPersonId": "",
                    "riskDealPersonName": item.riskDealPersonName ? item.riskDealPersonName : (this.readonly ? "" : JSON.parse(window.localStorage.getItem('userName')).userName),
                    "riskRemindTime": item.riskRemindTime,
                    "riskDealRequire": item.riskDealRequire,
                    "shouldRemovePerople": 0,
                    "riskLevel": item.riskLevel,
                    "taskName": item.taskName,
                    "taskNo": item.taskNo,
                }
                this.from.housePreventTaskDealInfoList.push(obj)
            }
            this.isDisabled.push(false)
            this.from.preventBaseInfoDtoList.push({
                "alreadyRemovePeople": item.alreadyRemovePeople,
                "shouldRemovePerople": item.shouldRemovePerople,
                "id": item.id,
                "isRemind": item.isRemind,
                "isDownNum": item.isDown,
                "planRemovePeople": item.planRemovePeople,
                "riskRemindUserId": item.riskRemindUserId,
                "riskRemindUserName": item.riskRemindUserName,
                "riskLevel": item.riskLevel,
                "zyzrrxm": item.zyzrrxm,
                "zyzrrsj": item.zyzrrsj,
                "disabledPeople": item.disabledPeople,
                "appraiseLevel": item.appraiseLevel
            })
            this.tableData[index] = []
            this.czrkhh[index] = this.newGuid()
            this.ids[index] = []
            this.getTransfer(item.idCard, index)
        })
        if (this.readonly) {
            this.getHousePreventTaskDealInfo(this.rowData[0].id)
        }
    }
}
</script>
<style lang="scss">
.BusinessProcessAdd {
    height: 100vh;
    overflow: auto;
    background: #ffffff;

    .title {
        width: 100%;
        font-size: 18px;
        text-align: center;
        font-weight: bold;
        line-height: 40px;
    }

    .jbxx {
        padding: 0 10px;
    }

    .van-field__label {
        color: #000;
    }

    .subTitle {
        width: 100%;
        height: 40px;
        line-height: 40px;
        font-weight: bold;
        position: relative;
        display: flex;
        align-items: center;
        padding-left: 10px;

        .line {
            width: 6px;
            height: 16px;
            background: #3f8ffc;
            display: inline-block;
            margin-right: 10px;
        }
    }

    .buttonfooter {
        padding: 10px;
        margin-top: 4px;
        display: flex;
        justify-content: space-between;

        .van-button {
            width: 47%;
        }
    }

    .popupDialog {
        width: 300px;
        border-radius: 11px;
        background-color: #fff;

        .dialog-title-text {
            line-height: 40px;
            text-align: center;
            border-bottom: 1px solid #ccc;
        }
    }
}
</style>
<style lang="scss">
.BusinessProcessAdd {

    .van-field__control,
    .van-field__error-message {
        text-align: right !important;
    }

    .van-field__label {
        width: auto !important;
    }
}
</style>
